This repository was archived by the owner on Sep 27, 2024. It is now read-only.
Add closed state to Mailbox #26
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is an alternative solution to the same problem described in #25 for sass/dart-sass#2279
On high level we have following logic in dart-sass, and we need a way to reliable stop the loop via mailbox:
Main Isolate:
Worker Isolate:
First,
Isolate.kill(priority: Isolate.immediate)
won't work whenmailbox.take()
is blocking. So, instead we callIsolate.kill()
first, and then send an empty message to signal the stopping. However, because the sending of empty message can fail, and then depending on the event loop timing, the worker isolate may process the isolate kill event before entering the loop one more time, which works as expected (killed before next iteration of loop); or it may get to the next iteration too quickly before the isolate kill event is processed, and thus cause the VM to lock up because the nextmailbox.take()
blocks the processing of kill event, causing the isolate to be appear non-responsive.Adding
close
method as designed in this PR will allow us to do:Main Isolate:
Worker Isolate:
Because
mailbox.close()
is guaranteed to deliver the signal viaStateError
on the ongoing or nextmailbox.take()
, we don't have the problem of failing to send empty message.